<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no" />
        <link rel="stylesheet" href="/static/lib/layui-v2.5.6/layui-v2.5.6/layui/css/layui.css">
		<title>微信登录</title>
		<style>
			.weichatlogin{
                margin: 0 auto;
            }
            .weichatlogin span{
                width: 100%;
                position: absolute;
                bottom: 20%;
                display:flex;
                flex-wrap:wrap;
                justify-content: space-between;
            }
            .weichatlogin span li{
                margin: 10px 10px;
                width: 100%;
                height: 36px;
                text-align: center;
                line-height: 36px;
                font-size: 22px;
                color: gray;
            }
            .layui-icon-loading{
                text-align: center;
                font-size: 36px;
                margin-left: 45%;
                color:gray;
            }
		</style>
	</head>
	<body>
		<div class="weichatlogin">
            <!-- <a href="javascript:history.go(-1);" class="loginTop"></a>
			<img src="./images/icon_weichat.png" alt=""> -->
			<span>
                <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                <li>正在登录...</li>
            </span>
		</div>
        <script src="/static/lib/jquery-1.9.1.min.js"></script>
        <script src="/static/lib/layer-v3.1.1/layer-v3.1.1/layer/layer.js"></script>
		<script>
			$(function(){
                var userAgent = navigator.userAgent.toLowerCase();

                if(userAgent.match(/MicroMessenger/i) == "micromessenger") {
                    var code = getUrlParam("code")
                    $.ajax({
                        type: "get",
                                //TODO:
                        url: "/Api/Web/wxLogin",
                        data: {code: code},
                        dataType: "json",
                        success: function(mag){
                            if (mag.code == "success") {
                                if (mag.data.role == "supplier") {
                                    if (mag.data.wxResponseUserInfo == undefined || mag.data.wxResponseUserInfo == null || mag.data.wxResponseUserInfo == '') {
                                        var userwxResponseUserInfo = ''
                                    }else{
                                        var userwxResponseUserInfo = mag.data.wxResponseUserInfo.headimgurl
                                    }
                                    var userwxusernameInfo = mag.data.nickname
                                    sessionStorage.setItem("sessionuserWxResponseUserInfo", userwxResponseUserInfo)
                                    sessionStorage.setItem("sessionuserWxusernameInfo", userwxusernameInfo)
                                    window.location = "./supplierlogin.html";
                                }else{
                                    layer.open({
                                        content: '账号未获取店长身份',
                                        skin: 'msg',
                                        time: 2 //2秒后自动关闭
                                    });
                                }
                            }else{
                                layer.open({
                                    content: mag.msg,
                                    skin: 'msg',
                                    time: 2 //2秒后自动关闭
                                });
                            }
                        },
                        error: function(){
                            layer.open({
                                content: '服务器错误，请退出重新登录',
                                skin: 'msg',
                                time: 2 //2秒后自动关闭
                            });
                        }
                    })
                }
            })


            function getUrlParam(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
				var context = "";
				if (r != null){
					context = r[2];
					reg = null;
					r = null;
				}
				return context == null || context == "" || context == "undefined" ? "" : context;
			}
		</script>
	</body>
</html>
